<?php
include_once '../samepart/header.php';
?>

<title>No.2商城-订单列表</title>
<script type="text/javascript">
    //console.log("test:"+'<?php //echo $_GET['isOLogin'] ?>//')
</script>


<div class="container" style="background-color: white;">
    <div class="row" style="margin-left: 40px">
        <h3>我的订单列表&nbsp;&nbsp;
            <small>温馨提示：<em></em>有<font color="red" id='sm'>
                </font>个订单</small></h3>
    </div>
    <div class="row" style="margin-top: 40px; height:70%;">
        <div class="col-md-12 table-responsive">
            <table id="tb_list" class="table table-striped table-hover table-bordered table-condensed">
            </table>
        </div>
    </div>
</div>
<!-- 底部 -->
<?php include_once '../samepart/footer.php' ?>


<script>
    /**
     *
     * */
    $(function () {
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.User.getUserInfoByUserName",
            type: "get",
            data: {
                "user_name": '<?php echo $_SESSION["username"]?>'
            },
            dataType: "JSON",
            success: function (re) {
                // var Uid=re.data.info.id
                getOrderInfo(re.data.info.id);
                console.log(re.data.info.id)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    })

    /**
     我的订单
     */
    function getOrderInfo(Uid) {
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.Order.getOrderInfoByUid",
            type: "get",
            data: {
                "user_id": Uid
            },
            dataType: "JSON",
            success: function (re) {
                var u_data = re.data.info;
                var s = "";
                var a = "";
                var sm = "";
                var sm = u_data.length;
                for (var i = 0; i < u_data.length; i++) {
                    var d_id = u_data[i]['id'];
                    // console.log(d_id)
                    var d_money = u_data[i]['money'];
                    var d_zt = u_data[i]['flag'];
                    var d_uaid = u_data[i]['uaid'];

                    if (d_zt == 1) {
                        d_zt = '未支付'
                    } else if (d_zt == 2) {
                        d_zt = '已支付,待发货'
                    } else if (d_zt == 3) {
                        d_zt = '已发货,待收货'
                    } else if (d_zt == 4) {
                        d_zt = '已收货，未评分'
                    } else {
                        d_zt = '订单完成'
                    }
                    var d_time = u_data[i]['createtime'];
                    j = i + 1
                    a += "<tr><th>" + j + "</th>" +
                        "<th>" + d_id + "</th>" +
                        "<th>" + d_money + "</th>" +
                        "<th>" + d_time + "</th>" +
                        "<th style='" + "color:red'" + ">" + d_zt + "</th>" +
                        "<th id='ddd'>" + getUserAddressInfo(d_uaid) + "</th>" +
                        "<th>" + "<a href='" + "orderDetail.php?actionOrderId=" + d_id +
                        "'><button type='button' class='btn btn-danger btn-sm'>" + "订单详情" + "</button>" + "</a>" +
                        "<a href='" + "deleteOrderSuccess.php?actionDelOrderId=" + d_id +
                        "'><button type='button' class='btn btn-danger btn-sm'>" + "删除订单" + "</button>" + "</a>" +
                        "</th></tr>"


                }
                s += "<tr><th>" + "序号" + "</th>" + "<th>" + "订单编号" + "</th>" +
                    "<th>" + "总金额" + "</th>" + "<th>" + "订单时间" + "</th>" +
                    "<th>" + "订单状态" + "</th>" +
                    "<th>" + "收货地址" + "</th>" +
                    "<th>" + "操作" + "</th></tr>" + a

                $("#tb_list").html(s);
                $("#sm").html(sm);
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    }


    /**地址 */
    function getUserAddressInfo(uaId) {
        var result = ''
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.UserAddress.getUserAddressByUaId",
            type: "get",
            data: {
                "ua_id": uaId
            },
            dataType: "JSON",
            success: function (re) {
                var u_data = re.data.info;
                result = u_data.detail;
                // console.log("result:"+result)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return result;
    }


</script>